package com.czl.module_service.adapter

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.tengyun.InventoryAssetBean
import com.czl.base.data.bean.tengyun.PurchaseOrderBean
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemPurchaseCardInfoBinding
import com.czl.module_service.fragment.purchase.PurchaseApplyInfoFragment
import com.google.zxing.common.StringUtils

class PurchaseApplyCardInfoAdapter(private val fragment: PurchaseApplyInfoFragment) :
    BaseQuickAdapter<PurchaseOrderBean, BaseDataBindingHolder<ItemPurchaseCardInfoBinding>>(
        R.layout.item_purchase_card_info
    ) {

    override fun convert(
        holder: BaseDataBindingHolder<ItemPurchaseCardInfoBinding>,
        item: PurchaseOrderBean,
    ) {
        if (item.planPurchaseFee != null) {
            item.planPurchaseFee = String.format("%.2f",item.planPurchaseFee.toString().toDouble())
        }
        if (item.fileList?.isNotEmpty() == true) {
            val fileUrl = item.fileList?.get(0)?.fileUrl
            if (fileUrl!!.contains(".jpg") || fileUrl!!.contains(".jpeg") || fileUrl!!.contains(".png")) {
                item.fileUrl = item.fileList?.get(0)?.fileUrl
            }
        }
        holder.dataBinding?.run {
            data = item
            adapter = this@PurchaseApplyCardInfoAdapter
            executePendingBindings()
        }
    }

    val onImageClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is PurchaseOrderBean) {
            if (it.fileUrl!!.contains(".jpg") || it.fileUrl!!.contains(".jpeg") || it.fileUrl!!.contains(".png")) {
                val bundle = Bundle()
                bundle.putString(AppConstants.BundleKey.SHOW_BIG_IMG, it.fileUrl)
                fragment.startContainerActivity(
                    AppConstants.Router.Service.F_SERVICE_SHOW_BIG_IMG,
                    bundle
                )
            }
        }
    })
}
